<?php
header("Content-Type: text/html; charset=utf-8");
?>

<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--  1.bootstrap引入  -->
    {{--    <link href="{{ asset('/bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">--}}
</head>

<meta name="csrf-token" content="{{ csrf_token() }}">
<script src=" {{ asset('/js/jquery-1.8.3.min.js') }} "></script>

<center>
    <table border="1">
        <h2><a href="index">添加一条数据</a></h2>
        <tr>
            <th>用户名</th>
            <th>密码</th>
            <th>操作</th>
        </tr>

        @forelse($list as $key=> $v)
            <tr>
                <td>{{ $v->username }}</td>
                <td>{{ $v->password }}</td>
                <td><a href="javascript:void(0);" onclick="delete_order('{{ $v->id }}')">删除</a>
                    <a href="{{url('/test/update')}}?id={{$v->id}}">修改</a></td>
            </tr>
        @empty
            <p>没有用户</p>
        @endforelse
    </table>
</center>

<div style='text-align:center;'>
    {{ $list->links() }}
</div>
<div class="badge" style="width:100%;text-align:center;font-size:18px;margin-bottom:70px;" >
    共{{ $list->total() }}条数据
</div>




<script>
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });
    // 获取 token
    var _token = $('meta[name="csrf-token"]').attr('content');
    var url = "{{ url('/test/del') }}";


    function delete_order(order_id){
//        alert(order_id)
        $.ajax({
            type:'post',
            url:url,
            data:{
                order_id:order_id,
                _token:_token
            },
            async:true,
            dataType:"json",
            success:function(msg){
                if(msg==1){
                    alert("删除成功");
                    window.location.reload();
                }
                if(msg==0){
                    alert("删除失败");
                    window.location.reload();
                }
            }
        })
    }

</script>

